package com.example.qxfw.dzzh.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.PotentialPoints;
import com.example.qxfw.dzzh.service.ZdglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@ApiIgnore
@Api(tags = "地质灾害-灾点管理")
@RestController
@CrossOrigin
@RequestMapping("/zdtgl")
public class ZdglController {
    @Autowired
    private ZdglService zdglService;

    @ApiOperation("所属乡")
    @RequestMapping("/selectCounty")
    public SysResult selectCounty(){
        List<String> countryList = zdglService.selectCountry();
        return SysResult.success(countryList);
    }

    @ApiOperation("灾害类型")
    @RequestMapping("/selectType")
    public SysResult selectType(){
        List<String> typeList = zdglService.selectType();
        return SysResult.success(typeList);
    }


    @ApiOperation("查询")
    @RequestMapping("/selectByTypeAndCountyOfTorrentPotentialPoints")
    public SysResult selectByTypeAndCountyOfTorrentPotentialPoints(@Param("type") String type, @Param("country")String country){
        List<PotentialPoints> tpp = zdglService.selectByTypeAndCountyOfTorrentPotentialPoints(type, country);
        return SysResult.success(tpp);
    }

    @ApiOperation("添加")
    @RequestMapping("/insertOneDate")
    public SysResult insertOneDate(@RequestBody PotentialPoints points){
        PotentialPoints result = zdglService.insertOneDate(points);
        if (result != null) {
            return SysResult.success(result);
        }else {
            return SysResult.fail("插入数据失败！！！");
        }
    }

    @ApiOperation("删除")
    @DeleteMapping("/deleteById")
    public SysResult deleteById(String ppId){
        int result = zdglService.deleteById(ppId);
        return SysResult.success(result);
    }

    @ApiOperation("修改")
    @PutMapping("/updateById")
    public SysResult updateById(@RequestBody PotentialPoints points){
        PotentialPoints result = zdglService.updateById(points);
        if (result != null){
            return SysResult.success(result);
        }else {
            return SysResult.fail("更新数据失败！！！");
        }

    }




}
